﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.AnswerInChannelFormFields.Service
{
    public class AnswerInChannelFormFieldAppService : BaseAppService, IAnswerInChannelFormFieldAppService
    {
        private IAnswerInChannelFormFieldDomainService _domainService;

        public AnswerInChannelFormFieldAppService(IAnswerInChannelFormFieldDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELFORMFIELD, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELFORMFIELD, AuditAction.CREATE)]
        public AnswerInChannelFormFieldDto Add(Guid formId, AnswerInChannelFormFieldCreateDto dto)
        {
            var answerInChannelFormField = Mapper.Map<AnswerInChannelFormField>(dto);
            answerInChannelFormField.FormId = formId;
            answerInChannelFormField = _domainService.Create(answerInChannelFormField);
            return Mapper.Map<AnswerInChannelFormFieldDto>(answerInChannelFormField);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELFORMFIELD, AuditAction.UPDATE)]
        public AnswerInChannelFormFieldDto Update(Guid id, AnswerInChannelFormFieldUpdateDto dto)
        {
            var answerInChannelFormFieldUpdateBo = Mapper.Map<AnswerInChannelFormFieldUpdateBo>(dto);
            answerInChannelFormFieldUpdateBo.Id = id;
            AnswerInChannelFormField answerInChannelFormField = _domainService.Update(answerInChannelFormFieldUpdateBo);
            return Mapper.Map<AnswerInChannelFormFieldDto>(answerInChannelFormField);
        }

        public AnswerInChannelFormFieldDto Get(Guid id ,string include = "")
        {
            AnswerInChannelFormField answerInChannelFormField = _domainService.Get(id,include);
            return Mapper.Map<AnswerInChannelFormFieldDto>(answerInChannelFormField);
        }

        public IEnumerable<AnswerInChannelFormFieldDto> GetList(Guid formId, string include= "")
        {
            IEnumerable<AnswerInChannelFormField> list = _domainService.GetByFormId(formId, include);
            return Mapper.Map<IEnumerable<AnswerInChannelFormFieldDto>>(list);
        }
    }
}
